home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / distutils / spawn.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  6KB  |  188 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. """distutils.spawn
  5.  
  6. Provides the 'spawn()' function, a front-end to various platform-
  7. specific functions for launching another program in a sub-process.
  8. Also provides the 'find_executable()' to search the path for a given
  9. executable name.
  10. """
  11. __revision__ = '$Id$'
  12. import sys
  13. import os
  14. from distutils.errors import DistutilsPlatformError, DistutilsExecError
  15. from distutils import log
  16.  
  17. def spawn(cmd, search_path = 1, verbose = 0, dry_run = 0):
  18.     """Run another program, specified as a command list 'cmd', in a new process.
  19.  
  20.     'cmd' is just the argument list for the new process, ie.
  21.     cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
  22.     There is no way to run a program with a name different from that of its
  23.     executable.
  24.  
  25.     If 'search_path' is true (the default), the system's executable
  26.     search path will be used to find the program; otherwise, cmd[0]
  27.     must be the exact path to the executable.  If 'dry_run' is true,
  28.     the command will not actually be run.
  29.  
  30.     Raise DistutilsExecError if running the program fails in any way; just
  31.     return on success.
  32.     """
  33.     if os.name == 'posix':
  34.         _spawn_posix(cmd, search_path, dry_run = dry_run)
  35.     elif os.name == 'nt':
  36.         _spawn_nt(cmd, search_path, dry_run = dry_run)
  37.     elif os.name == 'os2':
  38.         _spawn_os2(cmd, search_path, dry_run = dry_run)
  39.     else:
  40.         raise DistutilsPlatformError, "don't know how to spawn programs on platform '%s'" % os.name
  41.  
  42.  
  43. def _nt_quote_args(args):
  44.     '''Quote command-line arguments for DOS/Windows conventions.
  45.  
  46.     Just wraps every argument which contains blanks in double quotes, and
  47.     returns a new argument list.
  48.     '''
  49.     for i, arg in enumerate(args):
  50.         if ' ' in arg:
  51.             args[i] = '"%s"' % arg
  52.             continue
  53.     return args
  54.  
  55.  
  56. def _spawn_nt(cmd, search_path = 1, verbose = 0, dry_run = 0):
  57.     executable = cmd[0]
  58.     cmd = _nt_quote_args(cmd)
  59.     if search_path:
  60.         if not find_executable(executable):
  61.             pass
  62.         executable = executable
  63.     log.info(' '.join([
  64.         executable] + cmd[1:]))
  65.     if not dry_run:
  66.         
  67.         try:
  68.             rc = os.spawnv(os.P_WAIT, executable, cmd)
  69.         except OSError:
  70.             exc = None
  71.             raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  72.  
  73.         if rc != 0:
  74.             raise DistutilsExecError, "command '%s' failed with exit status %d" % (cmd[0], rc)
  75.  
  76.  
  77. def _spawn_os2(cmd, search_path = 1, verbose = 0, dry_run = 0):
  78.     executable = cmd[0]
  79.     if search_path:
  80.         if not find_executable(executable):
  81.             pass
  82.         executable = executable
  83.     log.info(' '.join([
  84.         executable] + cmd[1:]))
  85.     if not dry_run:
  86.         
  87.         try:
  88.             rc = os.spawnv(os.P_WAIT, executable, cmd)
  89.         except OSError:
  90.             exc = None
  91.             raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  92.  
  93.         if rc != 0:
  94.             log.debug("command '%s' failed with exit status %d" % (cmd[0], rc))
  95.             raise DistutilsExecError, "command '%s' failed with exit status %d" % (cmd[0], rc)
  96.  
  97. if sys.platform == 'darwin':
  98.     from distutils import sysconfig
  99.     _cfg_target = None
  100.     _cfg_target_split = None
  101.  
  102. def _spawn_posix(cmd, search_path = 1, verbose = 0, dry_run = 0):
  103.     global _cfg_target, _cfg_target_split
  104.     log.info(' '.join(cmd))
  105.     exec_fn = None if dry_run else os.execv
  106.     exec_args = [
  107.         cmd[0],
  108.         cmd]
  109.     if sys.platform == 'darwin':
  110.         if _cfg_target is None:
  111.             if not sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET'):
  112.                 pass
  113.             _cfg_target = ''
  114.             if _cfg_target:
  115.                 _cfg_target_split = [ int(x) for x in _cfg_target.split('.') ]
  116.             
  117.         if _cfg_target:
  118.             cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
  119.             if _cfg_target_split > [ int(x) for x in cur_target.split('.') ]:
  120.                 my_msg = '$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' % (cur_target, _cfg_target)
  121.                 raise DistutilsPlatformError(my_msg)
  122.             env = dict(os.environ, MACOSX_DEPLOYMENT_TARGET = cur_target)
  123.             if not search_path or os.execvpe:
  124.                 pass
  125.             exec_fn = os.execve
  126.             exec_args.append(env)
  127.         
  128.     pid = os.fork()
  129.     if pid == 0:
  130.         
  131.         try:
  132.             exec_fn(*exec_args)
  133.         except OSError:
  134.             e = None
  135.             sys.stderr.write('unable to execute %s: %s\n' % (cmd[0], e.strerror))
  136.             os._exit(1)
  137.  
  138.         sys.stderr.write('unable to execute %s for unknown reasons' % cmd[0])
  139.         os._exit(1)
  140.     else:
  141.         while None:
  142.             
  143.             try:
  144.                 (pid, status) = os.waitpid(pid, 0)
  145.             except OSError:
  146.                 exc = None
  147.                 import errno as errno
  148.                 if exc.errno == errno.EINTR:
  149.                     continue
  150.                 raise DistutilsExecError, "command '%s' failed: %s" % (cmd[0], exc[-1])
  151.  
  152.             if os.WIFSIGNALED(status):
  153.                 raise DistutilsExecError, "command '%s' terminated by signal %d" % (cmd[0], os.WTERMSIG(status))
  154.             if os.WIFEXITED(status):
  155.                 exit_status = os.WEXITSTATUS(status)
  156.                 if exit_status == 0:
  157.                     return None
  158.                 raise None, "command '%s' failed with exit status %d" % (cmd[0], exit_status)
  159.             if os.WIFSTOPPED(status):
  160.                 continue
  161.                 continue
  162.             raise DistutilsExecError, "unknown error executing '%s': termination status %d" % (cmd[0], status)
  163.             continue
  164.             return None
  165.  
  166.  
  167. def find_executable(executable, path = None):
  168.     """Tries to find 'executable' in the directories listed in 'path'.
  169.  
  170.     A string listing directories separated by 'os.pathsep'; defaults to
  171.     os.environ['PATH'].  Returns the complete filename or None if not found.
  172.     """
  173.     if path is None:
  174.         path = os.environ['PATH']
  175.     paths = path.split(os.pathsep)
  176.     (base, ext) = os.path.splitext(executable)
  177.     if (sys.platform == 'win32' or os.name == 'os2') and ext != '.exe':
  178.         executable = executable + '.exe'
  179.     if not os.path.isfile(executable):
  180.         for p in paths:
  181.             f = os.path.join(p, executable)
  182.             if os.path.isfile(f):
  183.                 return f
  184.         
  185.         return None
  186.     return None
  187.  
  188.